<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
</head>

<body>
  <div id="app">
    <div v-if="isShow" ref="div">test</div>
    <button @click="isShow = !isShow">update</button>
  </div>

  <script>
    const vm = new Vue({
      el: "#app",
      data: {
        isShow: false,
      },
      beforeUpdate() {
        console.log("更新之前！");
        // 更新之前无法获取元素
        console.log(this.$refs.div);
      },
      updated() {
        console.log("更新之后！");
        // 更新之后才能回去新的元素
        console.log(this.$refs.div);
      }
    })
  </script>
</body>

</html>